package com.zuozuo.syn;

public class Demo1 {
    static int stcket = 10;
    static Object object = "lock";

    public static void main(String[] args) {
        Runnable runnable = () -> {
            while (true) {
                synchronized (object) {
                    if (stcket > 0) {
                        System.out.println(Thread.currentThread().getName() + "：抢到了第" + stcket + "张票");
                        stcket--;
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    } else
                        break;
                }
            }

        };
        new Thread(runnable).start();
        new Thread(runnable).start();
        new Thread(runnable).start();
    }
}
